package com.lanchewuyou.user.driver.layouts;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lanchewuyou.user.driver.R;

/**
 * 显示照片
 */
public class PhotoActivity extends AppCompatActivity {
    private Toolbar mToolbar;
    private ImageView photoImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        initViews();

        Glide.with(PhotoActivity.this)
                .load(url)
                .fitCenter()
                .thumbnail(0.1f)
                .placeholder(me.iwf.photopicker.R.drawable.ic_photo_black_48dp)
                .error(me.iwf.photopicker.R.drawable.ic_broken_image_black_48dp)
                .into(photoImg);
    }

    private void initViews() {
        mToolbar = (Toolbar) findViewById(R.id.photo_pager_toolbar);
        mToolbar.setTitle("照片");
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        photoImg = (ImageView) findViewById(R.id.photo_pager_img);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_photo, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
